package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mes.vo.plan.ReleaseVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.ProgPlanDetail;
import com.ruoyi.mes.service.IProgPlanDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产计划下达明细Controller
 *
 * @author LongAndHao
 * @date 2023-05-09
 */
@RestController
@RequestMapping("/mes/detail")
public class ProgPlanDetailController extends BaseController
{
    @Autowired
    private IProgPlanDetailService progPlanDetailService;

    /**
     * 查询生产计划下达明细列表
     */
    @PreAuthorize("@ss.hasPermi('mes:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProgPlanDetail progPlanDetail)
    {
        startPage();
        List<ProgPlanDetail> list = progPlanDetailService.selectProgPlanDetailList(progPlanDetail);
        return getDataTable(list);
    }

    /**
     * 导出生产计划下达明细列表
     */
    @PreAuthorize("@ss.hasPermi('mes:detail:export')")
    @Log(title = "生产计划下达明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProgPlanDetail progPlanDetail)
    {
        List<ProgPlanDetail> list = progPlanDetailService.selectProgPlanDetailList(progPlanDetail);
        ExcelUtil<ProgPlanDetail> util = new ExcelUtil<ProgPlanDetail>(ProgPlanDetail.class);
        util.exportExcel(response, list, "生产计划下达明细数据");
    }

    /**
     * 获取生产计划下达明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(progPlanDetailService.selectProgPlanDetailById(id));
    }

    /**
     * 新增生产计划下达明细
     */
    @PreAuthorize("@ss.hasPermi('mes:detail:add')")
    @Log(title = "生产计划下达明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProgPlanDetail progPlanDetail)
    {
        return toAjax(progPlanDetailService.insertProgPlanDetail(progPlanDetail));
    }

    /**
     * 修改生产计划下达明细
     */
    @PreAuthorize("@ss.hasPermi('mes:detail:edit')")
    @Log(title = "生产计划下达明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProgPlanDetail progPlanDetail)
    {
        return toAjax(progPlanDetailService.updateProgPlanDetail(progPlanDetail));
    }

    /**
     * 删除生产计划下达明细
     */
    @PreAuthorize("@ss.hasPermi('mes:detail:remove')")
    @Log(title = "生产计划下达明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(progPlanDetailService.deleteProgPlanDetailByIds(ids));
    }

    //*****************************
    /**
     * 计划下达
     * @param releaseVo
     * @return
     */
    @PostMapping("/release")
    public AjaxResult release(@RequestBody ReleaseVo releaseVo){
        return progPlanDetailService.release(releaseVo);
    }

    /**
     * 查 - 计划下达 -生产计划等
     * @param progId 生产计划id
     * @return
     */
    @GetMapping("/getList")
    public AjaxResult getList(@RequestParam Long progId){
        return success(progPlanDetailService.getList(progId));
    }

    /**
     * 撤回 - 生产计划 - 车间任务及物料等
     * @param id 生产计划明细id
     * @return
     */
    @DeleteMapping("/revokeProgPlanDetails")
    public AjaxResult revokeProgPlanDetails(@RequestParam Long id){
        return progPlanDetailService.revokeProgPlanDetails(id);
    }

}
